home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- * *
- * Copyright (c) 1992, 1993 Ronald Joe Record *
- * *
- * All rights reserved. No part of this program or publication may be *
- * reproduced, transmitted, transcribed, stored in a retrieval system, *
- * or translated into any language or computer language, in any form or *
- * by any means, electronic, mechanical, magnetic, optical, chemical, *
- * biological, or otherwise, without the prior written permission of: *
- * *
- * Ronald Joe Record (408) 458-3718 *
- * 212 Owen St., Santa Cruz, California 95062 USA *
- * *
- *************************************************************************/
-
- /*************************************************************************
- * *
- * Copyright (c) 1989... Hiram Clawson *
- * *
- * All rights reserved. No part of this program or publication may be *
- * reproduced, transmitted, transcribed, stored in a retrieval system, *
- * or translated into any language or computer language, in any form or *
- * by any means, electronic, mechanical, magnetic, optical, chemical, *
- * biological, or otherwise, without the prior written permission of: *
- * *
- * Hiram Clawson (408) 429-5647 *
- * P. O. Box 3178, Santa Cruz, California 95063-3178 USA *
- * *
- *************************************************************************/
- /*************************************************************************
- * rotwindow.c: Rotate the viewing window *
- * *
- * Written by Hiram Clawson. *
- * - 20 Mar 92 rr@sco.com (Ronald Joe Record) *
- * Ported to X11. *
- * - 23 Mar 92 rr@sco.com (Ronald Joe Record) *
- * Added TranslateWindow(), SetWindow(), ScaleWindow(), *
- * and TranslateView() *
- *************************************************************************/
- #include "globals.h"
-
- static triple translated = {0.0};
-
- void
- RotateWindow( angle, RotVector )
- double *angle; /* in degrees */
- triple *RotVector;
- {
- /*
- * Rotates the viewing window about the RotVector
- */
- triple rotated;
- double theta;
- double rotcos;
- double rotsin;
- double const1;
- extern void TranslateWindow();
-
- theta = *angle;
-
- /* VECTOR_X_SCALAR(translated, translated, -1.0); */
- /* TranslateWindow(translated); back before any translations */
- rotcos = cos( theta * radians_per_degree );
- rotsin = sin( theta * radians_per_degree );
- const1 = 1.0 - rotcos;
-
- rotate ( (triple *) & window_center , & rotated, RotVector,
- & rotcos, & rotsin, & const1 );
- window_center.x = rotated.x;
- window_center.y = rotated.y;
- window_center.z = rotated.z;
- rotate ( (triple *) & window_top , & rotated, RotVector,
- & rotcos, & rotsin, & const1 );
- window_top.x = rotated.x;
- window_top.y = rotated.y;
- window_top.z = rotated.z;
- rotate ( (triple *) & window_upper_right , & rotated, RotVector,
- & rotcos, & rotsin, & const1 );
- window_upper_right.x = rotated.x;
- window_upper_right.y = rotated.y;
- window_upper_right.z = rotated.z;
- rotate ( (triple *) & window_right , & rotated, RotVector,
- & rotcos, & rotsin, & const1 );
- window_right.x = rotated.x;
- window_right.y = rotated.y;
- window_right.z = rotated.z;
- rotate ( (triple *) & view_point , & rotated, RotVector,
- & rotcos, & rotsin, & const1 );
- view_point.x = rotated.x;
- view_point.y = rotated.y;
- view_point.z = rotated.z;
-
- view_point_constants(); /* always call when window is changed */
-
- /* VECTOR_X_SCALAR(translated, translated, -1.0); */
- /* TranslateWindow(translated); re-apply any translations */
-
- return;
- }
-
- void SetWindow(axis) /* Position the window on the x, y, or z axis */
- int axis;
- {
- extern double window_distance;
- extern triple window_center;
-
- if (axis == 1) { /* View window centered at (window_distance, 0, 0) */
- window_center.x = window_distance;
- window_center.y = 0.0;
- window_center.z = 0.0;
-
- window_top.x = window_distance;
- window_top.y = window_distance / 2.0;
- window_top.z = 0.0;
-
- window_right.x = window_distance;
- window_right.y = 0.0;
- window_right.z = window_distance / 2.0;
-
- window_upper_right.x = window_distance;
- window_upper_right.y = window_distance / 2.0;
- window_upper_right.z = window_distance / 2.0;
-
- view_point.x = window_distance +
- (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
- view_point.y = 0.0;
- view_point.z = 0.0;
- }
- else if (axis == 2) { /* Window centered at (0, window_distance, 0) */
- window_center.y = window_distance;
- window_center.x = 0.0;
- window_center.z = 0.0;
-
- window_top.y = window_distance;
- window_top.x = window_distance / 2.0;
- window_top.z = 0.0;
-
- window_right.y = window_distance;
- window_right.x = 0.0;
- window_right.z = window_distance / 2.0;
-
- window_upper_right.y = window_distance;
- window_upper_right.x = window_distance / 2.0;
- window_upper_right.z = window_distance / 2.0;
-
- view_point.y = window_distance +
- (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
- view_point.x = 0.0;
- view_point.z = 0.0;
- }
- else if (axis == 3) { /* Window centered at (0, 0, window_distance) */
- window_center.z = window_distance;
- window_center.x = 0.0;
- window_center.y = 0.0;
-
- window_top.z = window_distance;
- window_top.y = window_distance / 2.0;
- window_top.x = 0.0;
-
- window_right.z = window_distance;
- window_right.y = 0.0;
- window_right.x = window_distance / 2.0;
-
- window_upper_right.z = window_distance;
- window_upper_right.x = window_distance / 2.0;
- window_upper_right.y = window_distance / 2.0;
-
- view_point.z = window_distance +
- (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
- view_point.x = 0.0;
- view_point.y = 0.0;
- }
- if ((axis == 1) || (axis == 2) || (axis == 3)) {
- translated.x = translated.y = translated.z = 0.0;
- }
- view_point_constants(); /* always call when window is changed */
- }
-
- void
- TranslateWindow( TransVector )
- triple TransVector;
- {
- /*
- * Translates the viewing window TransVector units
- */
- POINT_PLUS_VECTOR(window_center, window_center, TransVector);
- POINT_PLUS_VECTOR(window_top, window_top, TransVector);
- POINT_PLUS_VECTOR(window_upper_right, window_upper_right, TransVector);
- POINT_PLUS_VECTOR(window_right, window_right, TransVector);
- POINT_PLUS_VECTOR(view_point, view_point, TransVector);
- POINT_PLUS_VECTOR(translated, translated, TransVector);
-
- view_point_constants(); /* always call when window is changed */
-
- return;
- }
-
- void
- ScaleWindow(xscalar, yscalar)
- double xscalar, yscalar;
- {
- /*
- * Scales the viewing window by a factor of xscalar horizontally
- * and yscalar vertically. Window center and view point remain unchanged.
- */
- triple svec;
-
- VECTORIZE(svec, window_top, window_center);
- VECTOR_X_SCALAR(svec, svec, yscalar);
- POINT_PLUS_VECTOR(window_top, window_top, svec);
- POINT_PLUS_VECTOR(window_upper_right, window_upper_right, svec);
-
- VECTORIZE(svec, window_right, window_center);
- VECTOR_X_SCALAR(svec, svec, xscalar);
- POINT_PLUS_VECTOR(window_right, window_right, svec);
- POINT_PLUS_VECTOR(window_upper_right, window_upper_right, svec);
-
- view_point_constants(); /* always call when window is changed */
-
- return;
- }
-
- void
- TranslateView( TransVector )
- triple TransVector;
- {
- /*
- * Translates the viewing point TransVector units
- */
- POINT_PLUS_VECTOR(view_point, view_point, TransVector);
-
- view_point_constants(); /* always call when window is changed */
-
- return;
- }
-